package com.briup.common.exception;

import com.briup.common.response.CodeAndMessageEnum;
import com.briup.common.response.Result;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

@RestControllerAdvice
@Slf4j
public class GlobalExceptionHandler {

    @ExceptionHandler(SystemException.class)
    public Result handleSystemException(SystemException exception){
        System.out.println("GlobalExceptionHandler.handleSystemException: " + exception);
        CodeAndMessageEnum codeAndMessage = exception.getCodeAndMessage();
        Integer code = codeAndMessage.getCode();
        String message = codeAndMessage.getMessage();
        return Result.error(code,message);
    }

}
